package com.hegaoye.resolver;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Slf4j
@Component
public class IpResolver implements KeyResolver {

  @Override
  public Mono<String> resolve(ServerWebExchange exchange) {

    String ip = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();

    log.info("ip:" + ip);

    return Mono.just(ip);
  }
}
